#!/usr/bin/perl

package Foo;
#use Class::C3;
#use Class::C3::Componentised;
use Class::Trigger;
use base 'Class::C3::Componentised';
sub component_base_class { "Foo" }

sub new {
    my $class = shift;
    bless{data=>'start:'},$class;
}

sub call{
    my $self = shift;
    $self->_package_call_trigger({pkg=>__PACKAGE__,func=>'call'});
    $self->{data} .= 'foo:'.$s;
    return $self->{data};
}

sub _package_call_trigger{
    my $self = shift;
    my $arg  = shift;
    my $package = $arg->{pkg};
    my $func = $arg->{func};
#warn "$package::$func";
    $self->call_trigger($package.'::'.$func);
    return;
}

package Foo::Bar1;
use base qw/ Foo /;

sub call{
    my $self = shift;
    $self->{data} .= 'bar1:';
    #$self->_package_call_trigger();
    $self->_package_call_trigger({pkg=>__PACKAGE__,func=>'call'});
    $self->next::method();
    return $self->{data};
}

sub fee{
    my $self = shift;
    return '10,000 yen';
}

package Foo::Bar2;
use base qw/ Foo /;

sub call{
    my $self = shift;
    $self->{data} .= 'bar2:';
    #$self->_package_call_trigger();
    $self->_package_call_trigger({pkg=>__PACKAGE__,func=>'call'});
    $self->next::method();
    return $self->{data};
}

package Foo::Hoge;
#use base qw/ Bar1 Bar2 /;
use base qw/Foo::Bar1/;

sub call{
    my $self = shift;
    $self->{data} .= 'hoge:';
    #$self->_package_call_trigger();
    $self->_package_call_trigger({pkg=>__PACKAGE__,func=>'call'});
    $self->next::method();
    return $self->{data};
}

#Class::C3::initialize();
#my $foo = new Bar();
#my $foo = new Foo();
#unshift @Hoge::ISA,'Bar2';
Foo::Hoge->load_components('Bar2');
my $foo = new Foo::Hoge();
#my $foo->load_components('Bar2');
#Foo::Hoge->add_trigger(foo_call=>sub{return 'FOO';});
$foo->add_trigger('Foo::call'=>sub{warn 'FOO';});
$foo->add_trigger('Foo::Bar1::call'=>sub{warn 'BAR1';});
$foo->add_trigger('Foo::Bar2::call'=>sub{warn 'BAR2';});
$foo->add_trigger('Foo::Hoge::call'=>sub{warn 'HOGE';});
my $call = $foo->call();
my $fee  = $foo->fee();


print "Call-data:: $call\n";
print "Fee-data:: $fee\n";
print "Bar1-ISA:: @Bar1::ISA\n";
print "Hoge-ISA:: @Hoge::ISA\n";



#sub p($) {
#    my $str = shift;
#    print "$str\n";
#}


#my $t = 'akihito1';
#p $t;
#p 'hoe';



